/*
 * Created by JFormDesigner on Mon Jul 01 14:01:01 CST 2024
 */

package scct.hys.ui;

import scct.hys.dao.CinemaDao;
import scct.hys.dao.MovieDao;
import scct.hys.model.Cinema;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author 26984
 */
public class DlgCinemaUpdate extends JDialog {
    int id;
    public DlgCinemaUpdate(Window owner, int id) {
        super(owner);
        initComponents();
        this.id = id;
        System.out.println("id:"+id);
        initView();
    }

    private void initView() {
        CinemaDao cinemaDao = new CinemaDao();
        Cinema cinema = cinemaDao.getCinemaById(id);
        System.out.println("cinema"+cinema);
        txtCinemaName.setText(cinema.getName());
        txtCinemaAddress.setText(cinema.getAddress());
        txtTotalseats.setText(cinema.getTotalSeats());
}

private void btnUpdate(ActionEvent e) {
    // TODO add your code here
    String name=txtCinemaName.getText();
    String address=txtCinemaAddress.getText();
    String totalseats=txtTotalseats.getText();
    CinemaDao cinemaDao=new CinemaDao();
    if (cinemaDao.updateCinema(id,name,address,totalseats)){
//        JOptionPane.showMessageDialog(this,"修改成功");
        dispose();
    }

}



    private void initComponents() {
//         JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
// Generated using JFormDesigner Evaluation license - 韩月生
label1 = new JLabel();
txtCinemaName = new JTextField();
label2 = new JLabel();
txtCinemaAddress = new JTextField();
label3 = new JLabel();
txtTotalseats = new JTextField();
btnUpdate = new JButton();
btnCancel = new JButton();

//======== this ========
var contentPane = getContentPane();
contentPane.setLayout(null);

//---- label1 ----
label1.setText("\u5f71\u9662\u540d\u79f0");
contentPane.add(label1);
label1.setBounds(new Rectangle(new Point(35, 42), label1.getPreferredSize()));
contentPane.add(txtCinemaName);
txtCinemaName.setBounds(100, 35, 150, txtCinemaName.getPreferredSize().height);

//---- label2 ----
label2.setText("\u5f71\u9662\u5730\u5740");
contentPane.add(label2);
label2.setBounds(new Rectangle(new Point(35, 87), label2.getPreferredSize()));
contentPane.add(txtCinemaAddress);
txtCinemaAddress.setBounds(100, 80, 150, txtCinemaAddress.getPreferredSize().height);

//---- label3 ----
label3.setText("\u603b\u5ea7\u4f4d\u6570");
contentPane.add(label3);
label3.setBounds(new Rectangle(new Point(35, 134), label3.getPreferredSize()));
contentPane.add(txtTotalseats);
txtTotalseats.setBounds(100, 127, 160, txtTotalseats.getPreferredSize().height);

//---- btnUpdate ----
btnUpdate.setText("\u786e\u5b9a\u4fee\u6539");
btnUpdate.addActionListener(e -> btnUpdate(e));
contentPane.add(btnUpdate);
btnUpdate.setBounds(new Rectangle(new Point(70, 200), btnUpdate.getPreferredSize()));

//---- btnCancel ----
btnCancel.setText("\u53d6\u6d88");
contentPane.add(btnCancel);
btnCancel.setBounds(new Rectangle(new Point(235, 200), btnCancel.getPreferredSize()));

{
    // compute preferred size
    Dimension preferredSize = new Dimension();
    for(int i = 0; i < contentPane.getComponentCount(); i++) {
        Rectangle bounds = contentPane.getComponent(i).getBounds();
        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
    }
    Insets insets = contentPane.getInsets();
    preferredSize.width += insets.right;
    preferredSize.height += insets.bottom;
    contentPane.setMinimumSize(preferredSize);
    contentPane.setPreferredSize(preferredSize);
}
setSize(400, 300);
setLocationRelativeTo(null);
//         JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }




    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - 韩月生
    private JLabel label1;
    private JTextField txtCinemaName;
    private JLabel label2;
    private JTextField txtCinemaAddress;
    private JLabel label3;
    private JTextField txtTotalseats;
    private JButton btnUpdate;
    private JButton btnCancel;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
